<template>
  <div
    class="icon-with-text"
    :class="{ selected }"
    :style="selected ? { backgroundColor: $store.getters.cssVar.menuBg } : {}"
    @click="handleClick"
  >
    <svg-icon
      class="icon"
      :className="className"
      :icon="icon"
      :color="color"
    ></svg-icon>
    <div class="text">{{ text }}</div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
const emits = defineEmits(['selected'])
defineProps({
  iconSize: {
    type: Number,
    default: 60
  },
  text: {
    type: String,
    required: true
  },
  selected: {
    type: Boolean,
    default: false
  },
  icon: {
    type: String,
    required: true
  },
  color: {
    type: String,
    required: true
  },
  // 图标类名
  className: {
    type: String,
    default: ''
  }
})
const handleClick = () => {
  emits('selected')
}
</script>

<style lang="scss" scoped>
.icon-with-text {
  display: flex;
  height: 80px;
  width: 80px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

::v-deep .icon {
  margin-bottom: 4px;
  height: 30px;
  width: 30px;
}

.text {
  font-size: 14px;
}

.icon-with-text.selected {
  // background-color: #409eff; /* 选中时背景颜色 */
  // background-color: #009fe8; /* 选中时背景颜色 */
  .icon {
    color: #fff;
  }
  .text {
    color: #fff;
  }
}

.icon-with-text:not(.selected) {
  background-color: #f5f5f5; /* 未选中时背景颜色 */
}
</style>
